package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.DTResponseDto;
import com.hualude.roadsign.dto.JsonMsgDto;
import com.hualude.roadsign.service.ActorMenuService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by xu-jiaHui on 2017/4/9.
 */
@Controller
@RequestMapping("/rds_actorMenu")
public class ActorMenuController {

    @Resource
    private ActorMenuService actorMenuService;

    @RequestMapping(value = "/getActorMenuByActorId")
    @ResponseBody
    public DTResponseDto getActorMenuByActorId(DTRequestDto dtRequestDto, Integer actorId) throws Exception {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = actorMenuService.getActorMenuByActorId(dtRequestDto, actorId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping(value = "/getMenu4List")
    @ResponseBody
    public JsonMsgDto getAuthority4List() throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(actorMenuService.getMenu4List());
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonMsgDto;
    }


    @RequestMapping(value = "/updateActorMenu")
    @ResponseBody
    public JsonMsgDto updateActorMenuByAmId(Integer amId, Integer powerInsert, Integer powerDelete, Integer powerUpdate,
                                            Integer powerSelect, Integer powerCheck) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(actorMenuService.updateActorMenuByAmId(amId, powerInsert, powerDelete, powerUpdate, powerSelect, powerCheck));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }


    @RequestMapping(value = "/addMenu")
    @ResponseBody
    public JsonMsgDto addMenuByActorId(Integer actorId, String menuIds) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(actorMenuService.addMenuByActorId(actorId, menuIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/deleteActorMenu")
    @ResponseBody
    public JsonMsgDto deleteActorMenuById(Integer amId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(actorMenuService.deleteActorMenuByAmId(amId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

}
